/******************* (C) COPYRIGHT 2022 CHU WEI TENG ***********************************************
**
**------------------ File Info ---------------------------------------------------------------------
** File name:      dwin_trans.h
** modified Date:  2022-05-10
** Last Version:   V1.0
** Descriptions: 
** 
**------------------ Modfication  log --------------------------------------------------------------
** Date       Who            Rev        Comments
----------------------------------------------------------------------------------------------------
   22/05/10  chuwt@qq.com    V1.00      created

****************************************************************************************************/
#ifndef __DWIN_TRANS_H__
#define __DWIN_TRANS_H__

#include "dwin_types_def.h"
#include "dwin_fifo.h"

/* Public define-----------------------------------------------------------------------------------*/
#define  PACK_DATA_SIZE       122

#define DWIN_SYSTEM_VAR_ADDR_VERSION        0x000F
#define DWIN_SYSTEM_VAR_ADDR_GETBACKLIGHT   0x0031
#define DWIN_SYSTEM_VAR_ADDR_SETBACKLIGHT   0x0082
#define DWIN_SYSTEM_VAR_ADDR_MUSIC          0x00A0
#define DWIN_SYSTEM_VAR_ADDR_CURRENTPAGE    0x0014
#define DWIN_SYSTEM_VAR_ADDR_JUMPPAGE       0x0084
#define DWIN_SYSTEM_REG_ADDR_TOUCH_EN       0x000B
#define DWIN_SYSTEM_VAR_ADDR_GETRTC         0x0010
#define DWIN_SYSTEM_VAR_ADDR_SETRTC         0x009c
/* Public typedef----------------------------------------------------------------------------------*/

typedef enum
{
    TRANS_DATA_RECV,
    TRANS_CMD_RECV,
}dwin_trans_state_t;

typedef struct
{
    uint8_t     head_high;
    uint8_t     head_low;
    uint8_t     length;
    uint8_t     cmd;
    uint8_t     addr_high;
    uint8_t     addr_low;
    uint8_t     data[PACK_DATA_SIZE];
}data_pack_t;

typedef struct 
{
    dwin_trans_state_t  dwin_state;
    dwin_fifo_t*        send_fifo;
    dwin_fifo_t*        data_fifo;
    dwin_fifo_t*        cmd_fifo;
}dwin_trans_t;

/* Public function---------------------------------------------------------------------------------*/
ret_t dwin_reg_read(uint16_t addr, void* data, uint8_t len);
ret_t dwin_reg_write(uint16_t addr, void* data, uint8_t len);
ret_t dwin_var_read(uint16_t addr, void* data, uint8_t len);
ret_t dwin_var_write(uint16_t addr, void* data, uint8_t len);

dwin_trans_t* dwin_trans_init(void);
ret_t dwin_trans_fini(void);
dwin_trans_t* dwin_trans_get(void);
ret_t dwin_trans_recv(dwin_trans_t* trans, void* data, uint16_t len);

#endif
